const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight+'px',
    customBar:app.globalData.customBar+'px',
    navheight:app.globalData.customBar-app.globalData.statusBarHeight+'px',
    navlist:['最新问答','热门问答'],
    navindex:0,
    list:[],
    intCurrPage:1,
    intPageCount:0,
    loading:false,
    loadingNo:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.getFeijiu_Get_ZxWDList();


  },
  changeNav:function (e) {
    var idx = e.currentTarget.dataset.idx;
    if (this.data.navindex != idx) {
      this.setData({
        list:[],
        intCurrPage:1,
        intPageCount:0,
        navindex:idx
      })
      if (idx == 0) {
        this.getFeijiu_Get_ZxWDList();
      }else{
        this.getFeijiu_Get_RmWDList();
      }
    }
  },
  getFeijiu_Get_ZxWDList:function () {
    var that = this;
    var api_input = {
      intCurrPage:this.data.intCurrPage
    }
    app.getDaoPost('api/FeijiuApp/Feijiu_Get_ZxWDList',api_input,function (r) {
      
      if (r.code == 200) {
        var data = r.data.data.ds;
        var words = that.data.list.concat(r.data.data.ds);
        that.setData({
          intPageCount:r.data.intPageCount,
          list:words,
          loading:false,
        })
      }
    })
  },
  getFeijiu_Get_RmWDList:function () {
    var that = this;
    var api_input = {
      intCurrPage:this.data.intCurrPage
    }
    app.getDaoPost('api/FeijiuApp/Feijiu_Get_RmWDList',api_input,function (r) {
      if (r.code == 200) {
        var data = r.data.data.ds;
        var words = that.data.list.concat(r.data.data.ds);
        that.setData({
          intPageCount:r.data.intPageCount,
          list:words,
          loading:false,
        })
      }
    })        
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

    if (this.data.intPageCount > this.data.intCurrPage) {
      this.setData({
        loading:true,
        intCurrPage:this.data.intCurrPage+1
      })      
      if (this.data.navindex == 0) {
        this.getFeijiu_Get_ZxWDList();
      }else{
        this.getFeijiu_Get_RmWDList();
      }      
    }else{
      this.setData({
        loadingNo:true
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  woyaotiwen:function () {
    if (app.checkFjLogin()) {
      wx.navigateTo({
        url: 'woyaotiwen'
      })
    }else{
      wx.navigateTo({
        url: '../login/index'
      })      
    }
  },
  todetaile:function (e) {
    var tqid = e.currentTarget.dataset.tqid;
    wx.navigateTo({
      url: 'detaile?tqid='+tqid
    })
  },
  tosearch:function () {
    wx.navigateTo({
      url: 'search'
    })
  },
  toback:function () {
    wx.navigateBack()
  }
})